
define(["picCarouse","city"],function(){
  var index = {
    ready: function(){
        bindEvent();
        setNodeWidth();
    }
  }



function bindEvent(){
   $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
      e.preventDefault()
      $(this).tab('show')
    })

	$(".tip404-close").click(function(){
		$(".tip404").slideUp();
	})

	$(document).scroll(function(){
		var height = $(document).scrollTop();
		var nodeHeight = $(".top-nav").outerHeight(true);
		if($(".tip404").is(":visible")){
			nodeHeight = nodeHeight + $(".tip404").outerHeight(true);
		}

		if(height >=nodeHeight){
			$("body").prepend($(".search-wrapper").addClass("fix-search"));
			$(".hotsearchCon").hide()
		}

		if(height < nodeHeight){
			$("#search-container").prepend($(".search-wrapper").removeClass("fix-search"));
			$(".hotsearchCon").show();
		}
	})

	$(window).resize(function(){ 
		setNodeWidth();
	})

	window.imgAnimate = $("#slide").MdsSlideFade({
		  pageNum: true,_width:'100%',_height:'100%',btn:false,time: '3000'
	});

	$("#J_tab_nav a").on("mousedown", function(){ 
		var node = $($(this).attr("href")).find("ul").parent();
		window.imgAnimate.MdsSlideFadeStop();

		 window.imgAnimate = node.MdsSlideFade({
		    pageNum: true,_width:'100%',_height:'100%',btn:false,time: '3000'
		  });
	})

/*<i
        class="icon-weather-cloudy"></i><i class="icon-weather-fog"></i><i class="icon-weather-hail"></i><i
        class="icon-weather-lightning"></i><i class="icon-weather-night"></i><i class=""></i><i
        class="icon-weather-pouring"></i><i class="icon-weather-rainy"></i><i class="icon-weather-snowy"></i><i
        class="icon-weather-sunny"></i><i class="icon-weather-sunset-down"></i><i class="icon-weather-sunset-up"></i><i
        class="icon-weather-sunset"></i><i class="icon-weather-windy-variant"></i><i class="icon-weather-windy"></i><i
        class="icon-web"></i><i class="icon-webcam"></i><i class="icon-weight-kilogram"></i><i
        class="icon-weight"></i><i class="icon-whatsapp"></i><i class="icon-wheelchair-accessibility"></i><i
        class="icon-white-balance-auto"></i><i class="icon-white-balance-incandescent"></i><i
        class="icon-white-balance-irradescent"></i><i class="">*/

  var month = new Date().getMonth()+1+"月"+new Date().getDay()+"日";
  $(".calendar_month").text(month);
  $(".calendar_week").text(getWeekDay());

  setWeather();
	
}

function getWeekDay(){ 
  var show_day=new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日'); 
  var time=new Date(); 
  var year=time.getYear(); 
  var month=time.getMonth(); 
  var date=time.getDate(); 
  var day=time.getDay(); 
  var hour=time.getHours(); 
  var minutes=time.getMinutes(); 
  var second=time.getSeconds(); 
  month<10?month='0'+month:month; 
  month=month+1; 
  hour<10?hour='0'+hour:hour; 
  minutes<10?minutes='0'+minutes:minutes; 
  second<10?second='0'+second:second; 
  return show_day[day-1]
}

function setWeather(){
  var weathweIcon = {
    "晴":"icon-white-balance-sunny",
    "多云":"icon-weather-partlycloudy",
    "阴":"icon-weather-cloudy"
  }
   var this_ity;
    $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) {
        if (remote_ip_info.ret == '1') {
          this_ity=remote_ip_info.city;
            var myDate = new Date();
            var thisDate=myDate.getMonth()+1;
            $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) {
                $.ajax({
                    type: "GET",
                    url: "http://wthrcdn.etouch.cn/weather_mini?citykey="+constCity[this_ity],
                    dataType: "json",
                    success: function(data){
                        if(data.status==1000){
                          var _weather = data.data.forecast[0];

                          var html = '<div class="weather" monkey="weather" id="weather">'
                                      +'<a href="#" class="weather__item weather__city s-wea" data-hook="modify"><span class="weather__city-name" data-hook="name">'+this_ity+'</span></a>'
                                      +'<a href="#" class="weather__item weather__pm25 s-wea" data-hook="pm25" monkey="pm25" style="display: none;"><span class="weather__pm25-text g-ib" data-hook="pm25-text">良</span></a>'
                                      +'<a href="http://www.baidu.com/s?word=%E6%88%90%E9%83%BD%E5%A4%A9%E6%B0%94&amp;tn=50000030_hao_pg&amp;ie=utf-8" class="weather__item weather__info s-wea" data-hook="today" alog-text="今天晴 24 ~ 13℃">'
                                      +'<i class="'+weathweIcon[_weather.type]+' weather-icon"></i>'
                                      +'<span class="weather__info-txt" data-hook="weather">'+_weather.type+'</span><span class="weather__info-temperature large-show" data-hook="tempera">'+_weather.high+'~'+_weather.low+'</span></a>'
                                      +'<a href="http://www.weather.com.cn/weather/101270101.shtml#7d" class="weather__item weather__site" title="7日天气" data-hook="site"> '
                                      +'<span class="weather__site-icon"></span></a>'
                                     +'</div>';

                         $("#weather_wrapper").html(html);
                        }else{
                            alert("获取数据错误")
                        }
                    }
                });
            });
//                return this_ity

        } else {
            alert('没有找到匹配的IP地址信息！');
        }
    });
}
function setNodeWidth(){	
	var dw = $(document).width();

	if(dw<=768){ 
		var _w = $("#famous_websites_content_mini").width()-16;
		$(".famous-websites-mini .famous-websites-item").width(parseInt(_w/3));
	}else{ 
		var _w = $("#famous_websites_content").width()-72;
		$(".famous-websites-item").width(_w/6);
	}

}

!function ($) {

  "use strict"; // jshint ;_;


 /* TAB CLASS DEFINITION
  * ==================== */

  var Tab = function (element) {
    this.element = $(element)
  }

  Tab.prototype = {

    constructor: Tab

  , show: function () {
      var $this = this.element
        , $ul = $this.closest('ul:not(.dropdown-menu)')
        , selector = $this.attr('data-target')
        , previous
        , $target
        , e

      if (!selector) {
        selector = $this.attr('href')
        selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
      }

      if ( $this.parent('li').hasClass('active') ) return

      previous = $ul.find('.active a').last()[0]

      e = $.Event('show', {
        relatedTarget: previous
      })

      $this.trigger(e)

      if (e.isDefaultPrevented()) return

      $target = $(selector)

      this.activate($this.parent('li'), $ul)
      this.activate($target, $target.parent(), function () {
        $this.trigger({
          type: 'shown'
        , relatedTarget: previous
        })
      })
    }

  , activate: function ( element, container, callback) {
      var $active = container.find('> .active')
        , transition = callback
            && $.support.transition
            && $active.hasClass('fade')

      function next() {
        $active
          .removeClass('active')
          .find('> .dropdown-menu > .active')
          .removeClass('active')

        element.addClass('active')

        if (transition) {
          element[0].offsetWidth // reflow for transition
          element.addClass('in')
        } else {
          element.removeClass('fade')
        }

        if ( element.parent('.dropdown-menu') ) {
          element.closest('li.dropdown').addClass('active')
        }

        callback && callback()
      }

      transition ?
        $active.one($.support.transition.end, next) :
        next()

      $active.removeClass('in')
    }
  }


 /* TAB PLUGIN DEFINITION
  * ===================== */

  $.fn.tab = function ( option ) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('tab')
      if (!data) $this.data('tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }

  $.fn.tab.Constructor = Tab

}(window.jQuery);

return index;

})

 
